import 'package:flutter/material.dart';
import 'package:xindong/common/xindong_sezhi.dart';
import 'package:xindong/common/xindong_define.dart';
import 'package:xindong/common/xindong_all.dart';
import 'package:xindong/manager/xindong_chat_singleton.dart';

class XinDongLiaoTianCommonWords extends StatelessWidget {
  const XinDongLiaoTianCommonWords({super.key});

  @override
  Widget build(BuildContext context) {
    if (XinDongAll.instance.chatCommonWords.isEmpty) return const SizedBox();
    return Container(
      height: 40,
      alignment: Alignment.topLeft,
      padding: const EdgeInsets.only(bottom: 10),
      child: ListView.separated(
        padding: const EdgeInsets.only(left: kPaddingValue, right: kPaddingValue),
        scrollDirection: Axis.horizontal,
        itemCount: XinDongAll.instance.chatCommonWords.length,
        itemBuilder: (context, index) {
          final model = XinDongAll.instance.chatCommonWords[index];
          return _buildItem(model.content);
        },
        separatorBuilder: (BuildContext context, int index) {
          return const SizedBox(width: 10);
        },
      ),
    );
  }

  Widget _buildItem(String content) {
    return GestureDetector(
      onTap: () => XinDongChatSingleton.instance.requestSendText(text: content),
      behavior: HitTestBehavior.opaque,
      child: Container(
        padding: const EdgeInsets.only(left: 8, right: 8),
        decoration: BoxDecoration(borderRadius: BorderRadius.circular(16), color: Colors.white),
        child: Row(
          children: [
            Text(
              content,
              style: const TextStyle(color: DZColors.contentColor, fontSize: 14, height: 1.2),
            ),
          ],
        ),
      ),
    );
  }
}
